/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.order.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author icanci
 * @date Created in 2021/04/28 11:39
 * @version 1.0
 */
@SuppressWarnings("all")
public class RegexPatterns {
    /**
     * email 验证
     */
    private static final String REGEX_EMAIL = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";
    /**
     * 手机号验证
     */
    private static final String REGEX_PHONE = "^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$";

    /**
     * 正则邮箱
     * @param email
     * @return
     */
    public static final boolean isEmail(String email) {
        Pattern compileEmail = Pattern.compile(REGEX_EMAIL);
        Matcher matcherEmail = compileEmail.matcher(email);
        return matcherEmail.matches();
    }

    /**
     * 正则手机号
     * @param phone
     * @return
     */
    public static final boolean isPhone(String phone) {
        Pattern compileEmail = Pattern.compile(REGEX_PHONE);
        Matcher matcherEmail = compileEmail.matcher(phone);
        return matcherEmail.matches();
    }
}
